package cloud.maque.admin.controller;

import cloud.maque.admin.annotations.TenantId;
import cloud.maque.admin.annotations.TenantQuery;
import cloud.maque.admin.domain.entity.MqTenantAccount;
import cloud.maque.admin.service.MqTenantAccountService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhuyf
 * @date 2023/4/25 19:36
 */
@RestController
@RequestMapping(value = "/tenant-account")
@Api(tags = "运维-租户接口")
public class TenantAccountController {

    @Resource
    private MqTenantAccountService AccountService;

    /**
     * 新增
     *
     * @date 2023/04/25
     **/
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public ResponseBodyVo<MqTenantAccount> insert(@RequestBody MqTenantAccount mqTenantAccount) {
        return ResponseBodyVo.Success(AccountService.saveAccount(mqTenantAccount));
    }

    /**
     * 刪除
     *
     * @date 2023/04/25
     **/
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    @TenantQuery
    public ResponseBodyVo<Boolean> delete(@PathVariable("id") String id, @TenantId String tenantId) {
        return ResponseBodyVo.Success(AccountService.delete(id, tenantId));
    }

    /**
     * 查询 根据主键 id 查询
     *
     * @date 2023/04/25
     **/
    @GetMapping("/load/{id}")
    @ApiOperation(value = "读取")
    public ResponseBodyVo<MqTenantAccount> load(@PathVariable("id") String id) {
        return ResponseBodyVo.Success(AccountService.getById(id));
    }

    /**
     * 查询 租户ID和账户类型查找
     *
     * @date 2023/04/25
     **/
    @PostMapping("/find-tenant-account")
    @ApiOperation(value = "查询 租户ID和账户类型查找")
    public ResponseBodyVo<MqTenantAccount> FindTenantAccount(@RequestBody MqTenantAccount account) {
        account.setDisabled(0);
        MqTenantAccount result = AccountService.getAccountByType(account);
        result.setAppSecret("");
        return ResponseBodyVo.Success(result);
    }

    /**
     * 查询 分页查询
     *
     * @date 2023/04/25
     **/
    @PostMapping("/list")
    @ApiOperation(value = "查询")
    @TenantQuery
    public ResponseBodyVo<List<MqTenantAccount>> pageList(@RequestBody PaginateDataResquest<MqTenantAccount> pageReq) {
        return ResponseBodyVo.Success(AccountService.list(pageReq));
    }
}
